<template>
  <!-- 下拉刷新 -->
  <div>
    <van-nav-bar
      title="商品列表"
      left-text="返回"
      left-arrow
      :fixed="true"
      @click-left="$router.go(-1)"
    />
    <!-- :immediate-check="false"上拉加载自带的清除默认的第一次触发事件 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      :immediate-check="false"
    >
      <div class="main">
        <hmshopping
          v-for="value in shoppingData"
          :key="value.id"
          :value="value"
          @click.native="$router.push({ path: `/details/${value.id}` })"
        ></hmshopping>
      </div>
    </van-list>
  </div>
</template>

<script>
import hmshopping from "../components/hmshopping";
import { shoppingList } from "../apis/get";
export default {
  components: {
    hmshopping,
  },
  data() {
    return {
      shoppingData: [],
      loading: false,
      finished: false,
      pageindex: 1,
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    onLoad() {
      this.pageindex++;
      this.init();
    },
    init() {
      shoppingList({ pageindex: this.pageindex }).then((res) => {
        // this.shoppingData = res.data.message;
        //展开，把新数组存在旧数组里面去
        // console.log(res);
        this.shoppingData = [...this.shoppingData, ...res.data.message];

        this.loading = false;
        if (res.data.message.length < 10) {
          this.finished = true;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
/deep/ .van-nav-bar__content {
  background-color: #26a2ff;

  .van-nav-bar__text,
  .van-icon {
    color: #fff;
  }
}
/deep/ .van-nav-bar__title {
  color: #fff;
}
</style>